package com.brush.web.controller.pig.safety;

import com.brush.common.core.controller.BaseController;
import com.brush.common.core.domain.R;
import com.brush.pig.domain.req.safety.IotDormSterilizeAddReq;
import com.brush.pig.domain.req.safety.IotDormSterilizeReq;
import com.brush.pig.domain.resp.safety.IotDormSterilrzeResp;
import com.brush.pig.service.IotDormSterilizeService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Api(tags = "后台-生猪消毒")
@RestController
@RequestMapping("/admin/pig/sterilize")
public class IotDormSterilizeController extends BaseController {
    @Autowired
    private IotDormSterilizeService iotDormSterilizeService;

    @ApiOperation(value = "查询信息")
    @GetMapping("/data")
    public R<PageInfo<IotDormSterilrzeResp>> pageination(IotDormSterilizeReq req) {
        PageInfo<IotDormSterilrzeResp> pageInfo = iotDormSterilizeService.pagination(req);
        return R.ok(pageInfo);
    }

    @ApiOperation(value = "新增")
    @PostMapping
    public R add(@RequestBody @Valid IotDormSterilizeAddReq req){
        boolean result = this.iotDormSterilizeService.add(req);
        return result?R.ok() : R.fail();
    }

    @ApiOperation(value = "根据id查询")
    @GetMapping(value = "/{id}")
    public R<IotDormSterilrzeResp> findById(@PathVariable(value = "id") Long id) {
        IotDormSterilrzeResp iotDormSterilrzeResp = this.iotDormSterilizeService.findById(id);
        return R.ok(iotDormSterilrzeResp);
    }

    @ApiOperation(value="删除")
    @DeleteMapping(value = "/{ids}")
    public R deleteById(@PathVariable(value = "ids") Long[] ids) {
        boolean result = this.iotDormSterilizeService.deleteById(ids);
        return super.isSuccess(result);
    }


}
